
import {addResizeListener,removeResizeListener} from 'element-ui/lib/utils/resize-event.js';
import dom from '@/utils/dom.js';
const ctx = 'rs_resize_context'
function createHandler(el, binding, vnode){

    return function(rect){
        if(vnode.context[binding.expression]){
            vnode.context[binding.expression](rect);
        }
    }
}
export default{
    bind(el, binding, vnode) {
        el[ctx] = createHandler(el, binding, vnode);
        addResizeListener(el,()=>{
            const rect = dom.getBoundingClientRect(el);
            el[ctx](rect);
        })
    },
    update(el, binding, vnode){
        el[ctx] = createHandler(el, binding, vnode);
    },
    // inserted(el, binding, vnode){
    //     console.log(arguments)
    // },
    // componentUpdated(el, binding, vnode){
    //     console.log(arguments)
    // },
    unbind(el, binding, vnode){
        removeResizeListener(el);
        delete el[ctx]
    }
}